struct Solution;

use std::cmp::{max, min};
impl Solution {
    pub fn max_area(nums: &Vec<i32>) -> i32 {
        let mut left = 0;
        let mut right = nums.len() - 1;
        let mut result = (right - left) * min(nums[left], nums[right]) as usize;
        while right > left {
            if nums[right] > nums[left] {
                left += 1;
            } else {
                right -= 1;
            }
            result = max(
                result,
                (right - left) * min(nums[left], nums[right]) as usize,
            );
        }
        result as i32
    }
}

fn main() {
    println!("answer is {}", Solution::max_area(&vec![1, 2, 4, 3]));
}
